package com.zx.baofu.alcohol.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zx.baofu.alcohol.mapper.PrizeMapper;
import com.zx.baofu.alcohol.model.Prize;
import com.zx.baofu.alcohol.model.Result;
import com.zx.baofu.alcohol.service.PrizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class PrizeServiceImpl implements PrizeService {
    @Autowired
    PrizeMapper prizeMapper;

    @Override
    public Result getAllPrize() {
        List<Prize> list=prizeMapper.getPrize(null);
        return new Result().success("查询成功",list);
    }

    @Override
    public Result getPrizeById(Long id) {
        //根据id查询单个
        List<Prize> prizes=prizeMapper.getPrize(id);

        return new Result().success("查询成功",prizes);
    }

    @Override
    public Result updatePrize(Prize prize) {
        int res=prizeMapper.updatePrize(prize);
        if (res <= 0){
            return new Result().fail("修改失败");
        }
        return new Result().success("修改成功");
    }

    @Override
    public Result insertPrize(Prize prize) {
        int res=prizeMapper.insertPrize(prize);
        if (res <= 0){
            return new Result().fail("添加失败");
        }
        return new Result().success("添加成功");
    }

}
